﻿using Microsoft.AspNetCore.Mvc;

namespace MvcMovie.Controllers
{
    public class LoginController : Controller
    {
        public IActionResult Index()
        {
            return View(); // 返回登录界面 (视图代码见下页) } }
        }

        //登录验证
        public IActionResult Check(string username, string pwd)
        {
            if (!String.IsNullOrEmpty(username) && username.Equals("zz") && !String.IsNullOrEmpty(pwd) && pwd.Equals("888"))
            {
                HttpContext.Session.SetString("username", username);
                //将登录的用户名作为登录凭证
                return RedirectToAction("Index", "Test");
            }
            TempData["error"] = "用户名或密码错";
            //显示登录错误信息(一次性),session长时间存储，基于session存储机制
            return RedirectToAction("Index", "Login");
        }

        // 注销
        [Route("Logout")]
        public IActionResult Logout()
        {
            HttpContext.Session.Clear();
            return RedirectToAction("Index", "Home");
        }

    }

}
